unit AEStack; interface uses Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils,Resources, Errors, Palettes, LowMem, AppleEvents,AEObjects, AERegistry, Errors, Math,Background,Analysis,Camera,Stacks,Projection, globals, Utilities, Edit, Filters, Graphics, Camera, PlugIns, Macros1, Macros2, File1, File2, Lut, Text, User, Msc, AEUtility, AEWIndow, AEPicture; function StackEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; inCommand: OSType):OSerr; FUNCTION FindStackAccessor (desiredClass: DescType; containerToken: AEDesc; containerClass: DescType; keyForm: DescType; keyData: AEDesc; VAR outToken: AEDesc; theRefCon: LongInt): OSErr; function StackGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; function StackPutData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; implementation { *************************************************************************************** Handles AppleEvents sent to a window that holds a picture. *************************************************************************************** } function StackEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; inCommand: OSType):OSerr; VAR theError,ignoreErr:OSErr; theWindow:WindowPtr; AutoSelectAll:Boolean; OldPicNum, NewPicNum: integer; theString, theName:str255; theShortValue, sStart, sEnd:integer; theExtendedValue:extended; answer, on:Boolean; theEnum:DescType; lastPt, pt:Point; fwidth, i, pic1, pic2, wn, old: integer; theLongValue:LongInt; xAdd, xMul: extended; begin if inToken^.name = 'rang' then begin inToken^.name := '----'; for wn := inToken^.thru downto inToken^.index do begin inToken^.containerWindow := PicWindow[wn]; inToken^.containerInfo := pointer(WindowPeek(PicWindow[wn])^.RefCon); StackEvents := StackEvents(inAppleEvent, reply, inToken, inCommand); end; exit(StackEvents); end; theWindow := inToken^.containerWindow; theError := noErr; StackEvents := noErr; if (theWindow = nil) or (info^.StackInfo = nil) then begin StackEvents := PictureEvents(inAppleEvent, reply, inToken, inCommand); exit(StackEvents); end; if inCommand = 'Inst' then answer := AddSlice(true) else if inCommand = 'delo' then DeleteSlice else if inCommand = 'AvgS' then AverageSlices else if inCommand = 'iRGB' then begin theError := GetAEBoolean(inAppleEvent,'dith',DitherColor); theError := GetAEEnum(inAppleEvent, 'mode', theEnum); if theEnum = 'xLUT' then RGBLut := ExistingLUT else if theEnum = 'sLUT' then RGBLut := SystemLUT else RGBLut := CustomLUT; ConvertRGBToEightBitColor(false); end else if inCommand = 'Proj' then begin with info^.StackInfo^ do begin if SliceSpacing <= 0.0 then SliceSpacing := 1.0; if DensitySlicing then with info^ do begin TransparencyLower := SliceStart; TransparencyUpper := SliceEnd; end; DoProjection; end; end else if inCommand = 'ReSl' then Reslice else theError := PictureEvents(inAppleEvent, reply, inToken, inCommand); StackEvents := theError; end; function StackGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; VAR theError:OSErr; begin theError := errAEDescNotFound; with inToken^ do begin if name = 'nSlc' then theError := ReturnShortProperty(reply, info^.StackInfo^.nSlices) else if name = 'Slc#' then theError := ReturnShortProperty(reply, info^.StackInfo^.CurrentSlice) else if name = 'SlcZ' then theError := ReturnExtendedProperty(reply, info^.StackInfo^.SliceSpacing) else theError := PictureGetData(inAppleEvent, reply, inToken); { inherit ! } end; StackGetData := theError; end; function StackPutData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; VAR theError:OSErr; begin StackPutData := noErr; with inToken^ do begin if name = 'SlcZ' then info^.StackInfo^.SliceSpacing := GetExtendedProperty(inAppleEvent) else StackPutData := PicturePutData(inAppleEvent, reply, inToken); { inherit ! } end; end; FUNCTION FindStackAccessor (desiredClass: DescType; containerToken: AEDesc; containerClass: DescType; keyForm: DescType; keyData: AEDesc; VAR outToken: AEDesc; theRefCon: LongInt): OSErr; VAR theError: OSErr; theName,theWindowName:Str255; theWindow: WindowPtr; theWindowN: integer; iLoop: integer; theID: LongInt; theInfo: InfoPtr; theEnum: DescType; xval:extended; BEGIN theWindow := nil; IF keyForm = formName THEN BEGIN if (keyData.descriptorType = 'long') or (keyData.descriptorType = 'shor') then begin theError := LongFromDesc(keyData, theID); theName := StringOf(theID:3); for iLoop := 1 to length(theName) do if theName[iLoop] = ' ' then theName[iLoop] := '0'; end else if keyData.descriptorType = 'doub' then begin theError := ExtendedFromDesc(keyData, xval); RealToString(xval,4,1, theName); for iLoop := 1 to length(theName) do if theName[iLoop] = ' ' then theName[iLoop] := '0'; end else theError := StringFromDesc(keyData, theName); if (theError = noErr) then for iLoop := 1 to nPics do BEGIN theWindowName := GetWindowName(PicWindow[iLoop]); theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) and (IUEqualString(theWindowName, theName) = 0) then theWindow := PicWindow[iLoop]; END; if theWindow = nil then begin MakeNewTokenDesc(theName, 'Stak', outToken); FindStackAccessor := noErr; exit(FindStackAccessor); end; END ELSE IF keyForm = formAbsolutePosition THEN begin theError := ShortFromDesc(keyData, theWindowN); theID := 0; IF theError = noErr then if (theWindowN < 1) then {oops, passed an ID rather than index } for iLoop := 1 to nPics do begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then begin theID := theID + 1; if theID = theWindowN then theWindow := PicWindow[iLoop]; end end else if theWindowN <= nPics then theWindow := PicWindow[theWindowN] end ELSE IF keyForm = formRelativePosition THEN begin theError := EnumFromDesc(keyData, theEnum); if (theError = noErr) then begin iLoop := info^.PicNum; if theEnum = kAENext then for theWindowN := info^.PicNum+1 to nPics do if theWindow = nil then begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then theWindow := PicWindow[theWindowN]; end; if theEnum = kAEPrevious then for theWindowN := info^.PicNum-1 downto nPics do if theWindow = nil then begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then theWindow := PicWindow[theWindowN]; end; end end ELSE IF keyForm = formPropertyID THEN begin theError := LongFromDesc(keyData, theID); if (theError = noErr) then for iLoop := 1 to nPics do BEGIN theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if theInfo^.PidNum = theID then theWindow := PicWindow[iLoop]; END end; IF theWindow = NIL THEN FindStackAccessor := errAENoSuchObject ELSE {create outToken that identifies the window} BEGIN MakeTokenDesc(theWindow, 'Stak', outToken); FindStackAccessor := noErr; end END; end.